#ifndef __PHT_H__
#define __PHT_H__
#include <stdio.h>
#include <pthread.h>
#include "shmem.h"
#include <sys/ipc.h>
#include <sys/shm.h>
#include <string.h>
#include "cJSON.h"
#include <stdlib.h>
#include "MQTTClient.h"
#include "list.h"
#include "msg_queue_peer.h"
#include <sqlite3.h>


#define ADDRESS         "tcp://localhost:1883"
#define ADDRESS_YUANYU  "mqtt.yyzlab.com.cn"
#define CLIENTID        "STMClientSub"
#define CLIENTID_FLUSH  "STMClientFLUSHSub"
#define CLIENTID_YUANYU "STMClientYUANYU"
#define TOPICPUB        "/app/data/up"
#define TOPIC_YUANYU    "3498854532/Device2AIOTSIM"
#define TOPICSUB        "/app/control/down"
#define QOS 1
#define TIMEOUT 10000L

typedef union equipment
{
    BOOL a;
    int b;
    double c;
} Equipment;

char version[32];

typedef struct shm_report
{
    int mode;
    int period;
} Shm_Report;

typedef struct shm_addr_port
{
    char addr[32];
    int port;
} Shm_Addr_Port;

typedef struct shm_stm
{
    int key;
    int type;
    Equipment val;
} Shm_Stm;

typedef struct shm_modbus
{
    int key;
    int type;
    int addr;
    Equipment val;
} Shm_Modbus;

typedef struct message
{
    long mtype;
    char mtext[256];
} Message;

typedef struct list_data
{
    int key;
    int type;
    Equipment val;
    struct list_head list;
}List_Data;

void *shm_updata_addr;      // 版本
void *shm_report_addr;      // 上报模式
void *shm_mqtt_server_addr; // mqtt地址端口
void *shm_mb_dev_addr;      // modbus地址端口
void *shm_stm_addr;         // 单片机信息
void *shm_modbus_addr;      // modbus信息


void *pthread_upload(void *arg);
//void *pthread_sqlite(void *arg);
void *pthread_control(void *arg);
void *pthread_yuanyuzhou(void *arg);


#endif